package com.medical.model;

import com.medical.domain.Account;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Date;

@Data
public class AccountModel extends Account implements UserDetails {
    private String urealName; // 用户真实姓名
    private Collection<? extends GrantedAuthority> authorities; // 认证

    // 新增构造方法
    public AccountModel(Long id, String uname, String urealName, String utype, String password, Collection<? extends GrantedAuthority> authorities) {
        super(id,uname,urealName,utype,password); // 调用父类构造方法
        this.urealName = urealName;
        this.authorities = authorities;
    }

    public AccountModel(Long id, String uname, String realname, String pwd, String phoneNumber, String utype, Date updatetime, Date createtime) {
        super(id, uname, pwd, phoneNumber, utype, updatetime, createtime, realname);
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities; // 返回 authorities
    }

    @Override
    public String getPassword() {
        return super.getPwd(); // 返回密码
    }

    @Override
    public String getUsername() {
        return super.getUname(); // 返回用户名
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

    // 新增 getter 和 setter 方法
    public String getUrealName() {
        return urealName;
    }

    public void setUrealName(String urealName) {
        this.urealName = urealName;
    }

    public void setAuthorities(Collection<? extends GrantedAuthority> authorities) {
        this.authorities = authorities;
    }
}
